using System;
using System.Collections.Generic;
namespace MicroMsg.UI.UserContrl
{
	public class MMCache<keyType, ValueType>
	{
		private Dictionary<keyType, ValueType> mDictDataSaver;
		private List<keyType> mListQueue;
		public int mNCacheSize;
		public MMCache(int nCacheSize = 100)
		{
			if (nCacheSize <= 0)
			{
				nCacheSize = 1;
			}
			this.mNCacheSize = nCacheSize;
			this.mDictDataSaver = new Dictionary<keyType, ValueType>();
			this.mListQueue = new List<keyType>();
		}
		public ValueType GetDataFromCache(keyType gparam_0)
		{
			if (this.mDictDataSaver.ContainsKey(gparam_0))
			{
				this.mListQueue.Remove(gparam_0);
				this.mListQueue.Insert(0, gparam_0);
				return this.mDictDataSaver.get_Item(gparam_0);
			}
			return default(ValueType);
		}
		public void AddDataToCache(keyType gparam_0, ValueType imgSource)
		{
			if (gparam_0 == null || imgSource == null)
			{
				return;
			}
			if (this.mDictDataSaver.ContainsKey(gparam_0))
			{
				this.mDictDataSaver.set_Item(gparam_0, imgSource);
				return;
			}
			this.mDictDataSaver.Add(gparam_0, imgSource);
			this.mListQueue.Insert(0, gparam_0);
			if (this.mDictDataSaver.get_Count() > this.mNCacheSize)
			{
				keyType keyType = this.mListQueue.get_Item(this.mListQueue.get_Count() - 1);
				this.mListQueue.RemoveAt(this.mListQueue.get_Count() - 1);
				if (this.mDictDataSaver.ContainsKey(keyType))
				{
					this.mDictDataSaver.Remove(keyType);
				}
			}
		}
		public bool Exist(keyType gparam_0)
		{
			return this.mDictDataSaver.ContainsKey(gparam_0);
		}
	}
}
